package com.ruoyi.web.controller.module.event;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.module.event.EventTerminalsRecord;
import com.ruoyi.system.service.module.event.IEventTerminalsRecordService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 巡检记录Controller
 *
 * @author ruoyi
 * @date 2023-12-25
 */
@Validated
@Api(value = "巡检记录控制器", tags = {"巡检记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/event/record")
public class EventTerminalsRecordController extends BaseController {

    private final IEventTerminalsRecordService eventTerminalsRecordService;

    /**
     * 查询巡检记录列表
     */
    @ApiOperation("查询巡检记录列表")
    @PreAuthorize("@ss.hasPermi('module:terminalRecord:list')")
    @GetMapping("/list")
    public TableDataInfo<EventTerminalsRecord> list(@Validated EventTerminalsRecord eventTerminalsRecord) {
        QueryWrapper<EventTerminalsRecord> qw = new QueryWrapper<>();

        TableDataInfo<EventTerminalsRecord> td = PageUtils.buildDataInfo(eventTerminalsRecordService.page(PageUtils.buildPage(),qw));
        List<EventTerminalsRecord> list = td.getRows();
        return td;
    }

    /**
     * 导出巡检记录列表
     */
    @ApiOperation("导出巡检记录列表")
    @PreAuthorize("@ss.hasPermi('module:terminalRecord:export')")
    @Log(title = "巡检记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<EventTerminalsRecord> export(@Validated EventTerminalsRecord eventTerminalsRecord) {
        List<EventTerminalsRecord> list = eventTerminalsRecordService.list();
        ExcelUtil<EventTerminalsRecord> util = new ExcelUtil<EventTerminalsRecord>(EventTerminalsRecord.class);
        return util.exportExcel(list, "巡检记录");
    }

    /**
     * 获取巡检记录详细信息
     */
    @ApiOperation("获取巡检记录详细信息")
    @PreAuthorize("@ss.hasPermi('module:terminalRecord:query')")
    @GetMapping("/{id}")
    public AjaxResult<EventTerminalsRecord> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Integer id) {
        EventTerminalsRecord eventTerminalsRecord = eventTerminalsRecordService.getById(id);
        return AjaxResult.success(eventTerminalsRecord);
    }

    /**
     * 新增巡检记录
     */
    @ApiOperation("新增巡检记录")
    @PreAuthorize("@ss.hasPermi('module:terminalRecord:add')")
    @Log(title = "巡检记录", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody EventTerminalsRecord eventTerminalsRecord) {
        return toAjax(eventTerminalsRecordService.save(eventTerminalsRecord) ? 1 : 0);
    }

    /**
     * 修改巡检记录
     */
    @ApiOperation("修改巡检记录")
    @PreAuthorize("@ss.hasPermi('module:terminalRecord:edit')")
    @Log(title = "巡检记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody EventTerminalsRecord eventTerminalsRecord) {
        return toAjax(eventTerminalsRecordService.updateById(eventTerminalsRecord) ? 1 : 0);
    }

    /**
     * 删除巡检记录
     */
    @ApiOperation("删除巡检记录")
    @PreAuthorize("@ss.hasPermi('module:terminalRecord:remove')")
    @Log(title = "巡检记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Integer[] ids) {
        return toAjax(eventTerminalsRecordService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
